package socketmvc.core.util.xpath;

public abstract class AbstractPathMatcher implements PathMatcher{
    /**
     * 字符串与通配符进行比较
     *
     * @param path     路径字符串
     * @param wildcard 匹配符/通配符
     * @return 匹配结果 true 代表匹配成功
     */
    @Override
    public boolean match(String path, String wildcard) {
        if (path == null || "".equals(path)){
            return false;
        }else
        if (path.indexOf("/") != path.lastIndexOf("/") && "/*".equals(wildcard)){
            return false;
        }else
        if ("*".equals(wildcard.replaceAll("^\\*+","*"))){
            return false;
        }else
        if ("/**".equals(wildcard)){
            return true;
        }
        return doMatch(path,wildcard);
    }

    protected abstract boolean doMatch(String path, String wildcard);
}
